# made by marchen
# time at 15/3/30
# index.coffee use by views/index.ejs


# get jquery object
navs = $ '#nav li'
underLine = $ '#underLine'
homeContainer = $ '#home'
serveContainer = $ '#serve'

bannerBtn1 = $ '#bannerBtn1'
bannerBtn2 = $ '#bannerBtn2'
bannerBtn3 = $ '#bannerBtn3'

# navs hover and click event
navs.hover ->
	underLine.stop()
	index = $(@).index()
	offset = parseInt $(@).outerWidth true
	marginLeft = parseInt $(@).css('margin-left')
	underLine.animate({
		left : (offset * index) + marginLeft
	},300)
, ->
	index = navs.index(navs.filter('.on'))
	offset = parseInt $(@).outerWidth true
	marginLeft = parseInt $(@).css('margin-left')
	underLine.animate({
		left : (offset * index) + marginLeft
	},300)

navs.click ->
	navs.removeClass 'on'
	$(@).addClass 'on'
	index = $(@).index()
	if index is 0
		#首页
		serveContainer.removeClass('in').addClass 'out'
		setTimeout ->
			homeContainer.css 'display', 'block'
			serveContainer.css 'display', 'none'
			homeContainer.removeClass('out').addClass 'in'
		,1000
	else if index is 1
		#服务细节
		homeContainer.removeClass('in').addClass 'out'
		serveContainer.css 'display', 'block'
		setTimeout ->
			homeContainer.css 'display', 'none'
			serveContainer.removeClass('out').addClass 'in'
		,1000

# banner event
bannerBtn1.click ->
	parent = $(@).parent()
	parent.addClass 'out'
	bannerBtn2.parent().show().addClass 'in'
	setTimeout ->
		parent.css('display', 'none')
	,1000

bannerBtn2.click ->
	parent = $(@).parent()
	parent.addClass 'out'
	bannerBtn3.parent().show().addClass 'in'
	setTimeout ->
		parent.css('display', 'none')
	,1000